package com.llt.system.controller.exam;


import com.llt.common.core.domain.R;
import com.llt.common.core.domain.TableDataInfo;
import com.llt.system.domain.exam.dto.ExamAddDTO;
import com.llt.system.domain.exam.dto.ExamEditDTO;
import com.llt.system.domain.exam.dto.ExamQueryDTO;
import com.llt.system.domain.exam.dto.ExamQuestionAddDTO;
import com.llt.system.domain.exam.vo.ExamDetailVO;
import com.llt.system.service.exam.IExamService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author llt
 * @since 2024-10-08
 */
@RestController
@RequestMapping("/exam")
@RequiredArgsConstructor
public class ExamController {

    private final IExamService examService;

    /**
     * 获取竞赛列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO dto) {
        return examService.list(dto);
    }

    /**
     * 添加竞赛
     */
    @PostMapping("/add")
    public R<String> examAdd(@RequestBody ExamAddDTO dto) {
        return examService.examAdd(dto);
    }

    /**
     * 竞赛中添加题目
     */
    @PostMapping("/question/add")
    public R<Void>  questionAdd(@RequestBody ExamQuestionAddDTO dto) {
        return examService.questionAdd(dto);
    }

    /**
     * 删除竞赛中的题目
     */
    @DeleteMapping("/question/delete")
    public R<Integer> questionDelete(Long examId, Long questionId) {
        return examService.questionDelete(examId, questionId);
    }

    /**
     * 竞赛详情
     */
    @GetMapping("/detail")
    public R<ExamDetailVO> detail(Long examId) {
        return examService.detail(examId);
    }

    /**
     * 删除竞赛
     */
    @DeleteMapping("/delete")
    public R<Void> deleteExam(Long examId) {
        return examService.deleteExam(examId);
    }

    /**
     * 编辑竞赛
     */
    @PutMapping("/edit")
    public R<Integer> edit(@RequestBody ExamEditDTO dto) {
        return examService.edit(dto);
    }

    /**
     * 发布竞赛
     */
    @PutMapping("/publish")
    public R<Void> publish(Long examId) {
        return examService.publish(examId);
    }

    /**
     * 撤销发布
     */
    @PutMapping("/cancelPublish")
    public R<Void> cancelPublish(Long examId) {
        return examService.cancelPublish(examId);
    }


}
